package com.supaur.demo.mybatis;

import org.omg.CORBA.PRIVATE_MEMBER;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author huangj
 * @date 2019/10/10
 */
public class MyInvokerHandler implements InvocationHandler {

    private Object target;

    public MyInvokerHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("测试自定义逻辑");
        return method.invoke(target, args);
    }


    public <T> T getProxy() {
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
    }


    public static void main(String[] args) {
        IMyProxy iMyProxy = new MyInvokerHandler(new MyProxy()).getProxy();
        iMyProxy.test();
    }

}
